export const arrayToTree = (
  array,
  { id = 'id', pid = 'pid', children = 'children', rootId = null } = {}
) => {
  const tree = array
  // console.log('array',array)
  // debugger
  tree.forEach((item) => {
    let index = tree.findIndex((item1) => item1[id] === item[pid])
    // console.log('item',index)
    if (index !== -1) {
      let item1 = Object.assign({}, tree[index])
      try {
        if (!item1.path.includes('layout')) {
          index = tree.findIndex((item2) => item2[id] === item1[pid])
        }
      } catch (error) {
        //   console.log('error', error, item1)
      }
      // console.log('item', item1, index)
      tree[index][children] = tree[index][children] || []
      tree[index][children].push(item)
    }
  })
  return tree.filter((item) => item[pid] === rootId)
}
